//
//  T3_1_Section_CCell.swift
//  Pods
//
//  Created by eme on 2017/4/14.
//
//


import UIKit
import RxSwift

/**
 owner:cy
 update:2016年12月14日15:23:29
 info: 首页 商品区域
 VC :  HomePageVc
 */
class T3_1_Section_CCell: UICollectionViewCell {
    
    @IBOutlet weak var brands_Cv: UICollectionView!
    
    var didSelectedBrandItem:((_ brandItem:T3ListModel) -> Void)?
    var brandsList = [T3ListModel]() {
        didSet {
            self.brands_Cv.reloadData()
        }
    }
    override func awakeFromNib() {
        
    }
}
// MARK: - UICollectionViewDataSource
extension T3_1_Section_CCell:UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{
        return self.brandsList.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "T3_1_CCell", for: indexPath) as!T3_1_CCell
        let item  = self.brandsList[indexPath.row]
        if indexPath.row % 4 == 0{
            cell.leftLine_V.isHidden = true
        }else{
            cell.leftLine_V.isHidden = false
        }
        let lineNum = (self.brandsList.count + 3)/4
        if indexPath.row <  (lineNum - 1) * 4 && lineNum > 1 {
            cell.bottomLine_V.isHidden = false
        }else{
            cell.bottomLine_V.isHidden = true
        }
        cell.item = item
        return cell
    }
    func numberOfSections(in collectionView: UICollectionView) -> Int{
        return 1
    }
}
extension T3_1_Section_CCell:UICollectionViewDelegate{
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
        let item = self.brandsList[indexPath.row]
        _ = "brandpage".openURL(["brid":item.internalIdentifier])
    }
}

extension T3_1_Section_CCell:UICollectionViewDelegateFlowLayout{
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize{
        return T3_1_CCell.cellSize
        
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets{
        return T3_1_CCell.cellEdgeInsets
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat{
       return T3_1_CCell.lineSpacing
    }
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat{
        return T3_1_CCell.interitemSpacing
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize{
        return CGSize.zero
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize{
       return CGSize.zero
    }
}
